package com.js.auth.client.interceptor;

import com.js.auth.client.config.ServiceAuthConfig;
import com.js.auth.client.config.UserAuthConfig;
import com.js.core.context.BaseContextHandler;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author ygl
 * @create 2018-11-05
 * @DESCRIPTION
 * 服务间用feign调用时，统一对header进行操作
 **/
@Slf4j
public class ServiceFeignInterceptor implements RequestInterceptor {

    @Autowired
    private UserAuthConfig userAuthConfig;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(userAuthConfig.getTokenHeader(), BaseContextHandler.getToken());
    }
}
